package com.niit.mobileDevide.datausage;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class DataUsageBean implements Writable {

    private double appUsageTime; // 应用程序使用时间 (min/day)
    private double screenOnTime; // 屏幕开启时间 (hours/day)
    private double batteryDrain; // 电池消耗 (mAh/day)
    private int numAppsInstalled; // 已安装应用数量
    private double dataUsage; // 数据使用量 (MB/day)

    public DataUsageBean() {}

    public DataUsageBean(double appUsageTime, double screenOnTime, double batteryDrain, int numAppsInstalled, double dataUsage) {
        this.appUsageTime = appUsageTime;
        this.screenOnTime = screenOnTime;
        this.batteryDrain = batteryDrain;
        this.numAppsInstalled = numAppsInstalled;
        this.dataUsage = dataUsage;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeDouble(appUsageTime);
        out.writeDouble(screenOnTime);
        out.writeDouble(batteryDrain);
        out.writeInt(numAppsInstalled);
        out.writeDouble(dataUsage);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        appUsageTime = in.readDouble();
        screenOnTime = in.readDouble();
        batteryDrain = in.readDouble();
        numAppsInstalled = in.readInt();
        dataUsage = in.readDouble();
    }

    @Override
    public String toString() {
        return String.format("%.2f,%.2f,%.2f,%d,%.2f", appUsageTime, screenOnTime, batteryDrain, numAppsInstalled, dataUsage);
    }

    public double getDataUsage() {
        return dataUsage;
    }

    public int getNumAppsInstalled() {
        return numAppsInstalled;
    }
}